import { ccs } from "../../util/services";
import { game } from "../control/game";
import { thingsModel } from "../gameType";
import { playerClass } from "./playerModel";
import { timeClass } from "./timeModel";
export default class things { 
    //事件类 玩家进行事件

    doThings(event: thingsModel, player: playerClass = game.playerMgr, timer: timeClass = game.timerMgr) {
        //时间
        timer.addTime(event.time, player);
        //增加属性
        event.effect.forEach(val => {
            player.heroInfo[val.key] += val.point;
        })
        //随机事件
        if(Math.random() >= 0.8) {
           let eventId = event.randomEvent[Math.floor(Math.random() * event.randomEvent.length - 1)];
           this.doRandomThing(eventId, player);
        }
    }
    //随机事件的进行
    doRandomThing(eventId: number, player: playerClass) {
        let event: thingsModel = ccs.dataMgr.getDataById("things", eventId );
        event.effect.forEach(val => {
            player.heroInfo[val.key] += val.point;
        })
    }

}